<?php 
if(!defined('INEZCMS')){
	exit('Access Denied');
}
if(empty($userlogininfo)){
    
    jump(SITEURL."/login.html", '您还没有登录!');
}
$ezuser=$ezhand->select("member","*","id=".$userlogininfo["uid"]);

    $pagesize=20;
    $ezuser["id"]=$userlogininfo["ezusername"];
	no_cache();    
	$do=$_GET['do']?$_GET['do']:'in';
	$page = !($_GET['page'])?'1':intval($_GET['page']);
	$page2=($page-1)*$pagesize;
	
	if($do=='in'){
		$total = $ezhand->count('message',"send_to_id='".$ezuser["id"]."'");
		$mgs_row=$ezhand->select_all('message',"*","send_to_id='".$ezuser["id"]."' order by id desc limit $page2,$pagesize");
	}
	elseif($do=='out'){
		$total = $ezhand->count('message'," send_from_id='".$ezuser["id"]."'");
		$mgs_row=$ezhand->select_all('message',"*"," send_from_id='".$ezuser["id"]."' order by id desc limit $page2,$pagesize");
	}
	elseif($do=='del'){
		$ids=$_GET['ids'];
		foreach($ids as $id){
			if($id>0){
				$sql="delete from ".$BIAOTOU."message where id='".$id."'";
				$ezhand->query($sql);
			}
		}
		jump('-1','删除成功');
	}
	elseif($do=='save_send'){
		$content=htmlspecialchars($_POST['content']);
        $toname=trim($_POST["tousername"]);
        $urow=$ezhand->select('member',"*","username='".$toname."'");
        $_SESSION["subject"]=trim($_POST["subject"]);
        $_SESSION["content"]=trim($_POST["content"]);        
        if(empty($urow)){
            
          jump('-1','用户没有找到!');  
        }
        
        $uid=$userlogininfo["uid"];
        $replyid=intval($_POST["replyid"]);
		if($content!=''){
			$field_arr=array('subject'=>trim($_POST["subject"]),'replyid'=>$replyid,'folder'=>'outbox','content'=>$content,'message_time'=>time(),'status'=>0,'send_to_id'=>$toname,'send_from_id'=>$ezuser['id'],'from_uid'=>$uid);
			$ezhand->insert('message', $field_arr,0);
		}
        $_SESSION["subject"]="";
        $_SESSION["content"]="";          
		jump('-1','发送成功');
	}
	elseif($do=='get_msg'){
	   $id=intval($_GET["id"]);
       
       $urow=$ezhand->select('message',"*","id='".$id."' and (send_from_id='".$ezuser["id"]."' or send_to_id='".$ezuser["id"]."')");
       if(empty($urow)){
         jump('-1','没有找到相关消息!'); 
       }
       
       
	}
	unset($ezhand);

?>